package hyg.q1;

/**
 * Created by brss on 2018/9/15.
 */
public class Drink {
    private int maxDrunk = 0;
    private int money;
    private int lid = 0;
    private int bottle = 0;
    public int drinkMilk(int maney) {
        this.money = maney;
        calu();
        int res = maxDrunk;
        maxDrunk = 0;
        lid = 0;
        bottle = 0;
        return maxDrunk;
    }
    private void calu() {
        if (money < 5 && lid < 4 && bottle < 3)
            return;
        if (money >= 5){
            int maxBuy = money / 5;
            maxDrunk += maxBuy;
            money = money - maxBuy * 5;
            lid+=maxBuy;
            bottle+=maxBuy;
        }
        if (lid >= 4) {
            int maxRep = lid / 4;
            maxDrunk += maxRep;
            lid = lid - maxRep * 4 + maxRep;
            bottle+=maxRep;
        }
        if (bottle >= 3) {
            int maxRep = bottle / 3;
            maxDrunk += maxRep;
            lid += maxRep;
            bottle = bottle - maxRep * 3 + maxRep;
        }
        calu();
    }
}
